<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>添加 kickstart 启动文件</title>
    {% load staticfiles %}
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    <link rel="stylesheet" href="{% static 'lib/layui/css/layui.css' %}">
    <link rel="stylesheet" href="{% static 'css/scroll-bar.css' %}">
    <link rel="stylesheet" href="{% static 'css/sub-page.css' %}">

    <link rel="stylesheet" href="//at.alicdn.com/t/font_693759_wytlyqhtdtj1nhfr.css">
</head>
<body>
<div class="ok-body">
    <!--面包屑导航区域-->
    <div class="ok-body-breadcrumb">
            <span class="layui-breadcrumb">
                <a><cite>首页</cite></a>
                <a><cite>系统推送</cite></a>
                <a><cite>kickstarts 管理</cite></a>
				<a><cite>添加kickstart信息</cite></a>
            </span>
        <a class="layui-btn layui-btn-small" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon layui-icon-refresh"></i>
        </a>
    </div>
    <!--form表单-->
    <form class="layui-form layui-form-pane ok-form">



        <div class="layui-form-item">
            <label class="layui-form-label">kickstart</label>
            <div class="layui-input-block">
                <input type="text" name="kickstart"  autocomplete="off" class="layui-input"
                       lay-verify="required">
            </div>
        </div>


        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">脚本内容</label>
            <div class="layui-input-block">
                <textarea name="context" placeholder="请输入脚本内容" class="layui-textarea"></textarea>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="add">添加</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<!--js逻辑-->
<script src="{% static 'lib/layui/layui.js' %}"></script>
<script>
    layui.use(['element', 'form', 'jquery', 'laydate'], function () {
        var element = layui.element;
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var laydate = layui.laydate;

        laydate.render({
            elem: '#birthday',
            type: "datetime"
        });

        form.on('submit(add)', function (data) {
            console.log(data.field);

            $.ajax({
                type: 'post',
                url: "{% url 'api_init_system_kickstart_add' %}", // ajax请求路径
                data: {
                    data: JSON.stringify(data.field),
                    csrfmiddlewaretoken: "{{ csrf_token }}",
                },
                dataType: 'json',
                success: function (data) {
                      if (data["status"] == 0) {
                        layer.msg(data["message"], {icon: 6, time: 1000, anim: 4}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                        });
                    } else  {
                        layer.msg(data["message"]);
                    }
                }
            });

            return false;
        });
    })
</script>
</body>
</html>